package com.forlove.app.qselect.hotlist.ui;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.forlove.app.R;
import com.forlove.app.common.base.ui.BaseFragment;
import com.forlove.app.common.utils.LogUtil;
import com.forlove.app.common.utils.StatusBarCompat;
import com.forlove.app.common.widget.recyview.BaseRecyclerAdapter;
import com.forlove.app.qselect.hotlist.adapter.HotlistAdapter;
import com.forlove.app.qselect.hotlist.entity.HotlistEntity;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * 榜单fragment
 * Created by yjl on 2017/9/28.
 */

public class HotlistFragment extends BaseFragment {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.toolbar_title)
    TextView toobarTitle;

    @BindView(R.id.list_hot)
    RecyclerView list_hot;

    private ArrayList<HotlistEntity> hotlistEntities = new ArrayList<>();

    private HotlistAdapter hotlistAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_hotlist;
    }

    @Override
    protected void initFragmentView() {
        initTitleBar();
        initHotlist();
    }


    /**
     * 初始化titlebar颜色
     */
    private void initTitleBar() {
        toobarTitle.setText("达人榜");
        toobarTitle.setTextColor(Color.parseColor("#ffffff"));
        toolbar.setBackgroundColor(Color.parseColor("#7a8df6"));
//        toolbar.inflateMenu(R.menu.menu_index_tab);//设置右边的图片
//        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
//            @Override
//            public boolean onMenuItemClick(MenuItem item) {
//                switch (item.getItemId()) {
//                    case R.id.menu_right:
//                        LogUtil.e("yjl", "点击右边");
//                        startActivity(new Intent(mContext, MineInfoActivity.class));
//                        break;
//                }
//                return true;
//            }
//        });
//        toolbar.setNavigationIcon(R.mipmap.tab_mine_sel);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.e("yjl", "点击左边");
//                startActivity(new Intent(mContext, MineFriendsActivity.class));
            }
        });

        StatusBarCompat.compat(getActivity(), Color.parseColor("#7a8df6"));
    }

    @Override
    public void onResume() {
        super.onResume();
        StatusBarCompat.compat(getActivity(), Color.parseColor("#7a8df6"));
    }

    private void initHotlist() {
        HotlistEntity hotlistEntity = new HotlistEntity();
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);
        hotlistEntities.add(hotlistEntity);

        hotlistAdapter = new HotlistAdapter(mContext, R.layout.item_hotlist_view, hotlistEntities);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        list_hot.setLayoutManager(linearLayoutManager);
        list_hot.setAdapter(hotlistAdapter);
        hotlistAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                startActivity(new Intent(mContext, HotlistDetailActivity.class));
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }
}

